<@t.header>
<link rel="stylesheet" href="${request.contextPath}/app/contract/css/contract-create.css">
</@t.header> <@t.body> <#if (invalid?? && invalid) || (notfound?? && notfound)>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong> 无效的合同信息！
</div>
<#elseif cannotedit?? && cannotedit>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong> 您无法编辑该信息！
</div>
<#elseif errortype?? && errortype>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong> 合同类型无效
	<a href="${request.contextPath}/contract/view/${data.id}">返回</a>
</div>
<#else>
<div class="navbar navbar-default navbar-fixed-top padding-0 margin-0">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#suredy-form-navbar">
				<span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
			</button>
			<span class="navbar-brand"> <i class="icon-paste icon-large"></i> 编辑${data.type.value}
			</span>
		</div>
		<div class="collapse navbar-collapse" id="suredy-form-navbar">
			<ul class="nav navbar-nav suredy-form-bar">
				<li>
					<a href="javascript:void(0);" class="submit-contract-info">
						<i class="icon-ok icon-large"></i>
						修改
					</a>
				</li>
				<li>
					<a href="javascript:void(0);" class="reset-form-info">
						<i class="icon-undo icon-large"></i>
						重置表单
					</a>
				</li>
			</ul>
		</div>
	</div>
</div>

<div class="container" style="padding-top: 60px;">
	<form class="form-create-contract" action="${request.contextPath}/dm/contract-edit" method="post">
		<input type="hidden" name="id" value="${data.id}" />
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">基本信息</h3>
			</div>
			<div class="panel-body" style="padding-bottom: 0;">
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 合同名称
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="name" value="${data.name}" placeholder="最多100个汉字">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 建设单位
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="companyA" value="${data.companyA}" readonly="readonly">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 承建单位
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="companyB" value="${data.companyB}" readonly="readonly">
							</div>
						</div>
					</div>
					<#if data.type.collection>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 项目实施单位
									</div>
								</div>
								<textarea rows="1" class="form-control not-empty" name="doUnit" readonly="readonly">${data.doUnit}</textarea>
							</div>
						</div>
					</div>
					</#if>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 合同编号
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="no" value="${data.no}" placeholder="最多50个字符">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> <#if data.moneyType=='TOTAL'> 合同总价 <#elseif data.moneyType=='SINGLE'> 合同单价 <#elseif data.moneyType=='DROP_POINT'> 合同降点 </#if>
									</div>
								</div>
								<#if data.moneyType=='TOTAL'> <input type="text" class="form-control not-empty number" name="price" value="${data.price}" placeholder="只能是数字">
								<div class="input-group-addon">元</div>
								<#else>
								<textarea rows="1" class="form-control not-empty" name="priceDes" style="resize: none;" onfocus="$(this).attr('rows', 5);" onblur="$(this).attr('rows', 1);" placeholder="最多500个汉字">${data.priceDes}</textarea>
								</#if>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 签订日期
									</div>
								</div>
								<input type="text" class="form-control not-empty datetimepicker" name="signDate" data-foot="false" data-format="yyyy-MM-dd" value="${(data.signDate?string('yyyy-MM-dd'))!''}" readonly="readonly">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 办结日期
									</div>
								</div>
								<input type="text" class="form-control not-empty datetimepicker" name="bjTime" data-foot="false" data-format="yyyy-MM-dd" value="${(data.bjTime?string('yyyy-MM-dd'))!''}" readonly="readonly" placeholder="请选择日期">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 经&nbsp;&nbsp;办&nbsp;&nbsp;人
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="jingban" value="${data.jingban}" placeholder="请填写经办人名称">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 联系方式
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="jingbanPhone" value="${data.jingbanPhone}" placeholder="请填写经办人联系方式">
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 合同工期 <small class="text-danger contract-days-helper" style="font-weight: bold; cursor: pointer;">？</small>
									</div>
								</div>
								<input type="text" class="form-control datetimepicker" name="contractStart" value="${(data.contractStart?string('yyyy-MM-dd'))!''}" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="开工日期">
								<div class="input-group-addon" style="border-left: none; border-right: none;">至</div>
								<input type="text" class="form-control datetimepicker" name="contractEnd" value="${(data.contractEnd?string('yyyy-MM-dd'))!''}" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="竣工日期">
								<div class="input-group-addon" style="border-left: none; border-right: none;">工期天数</div>
								<input type="text" class="form-control number" name="contractDays" value="${data.contractDays}" placeholder="工期天数">
								<div class="input-group-addon" style="border-left: none;">天</div>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<label class="checkbox-inline"> <input type="checkbox" name="needZbMoney" value="true"${((data.needZbMoney??&&data.needZbMoney)?string('checked',''))!''}> 需要质保金
							</label> <label class="checkbox-inline"> <input type="checkbox" name="needYfMoney" value="true"${((data.needYfMoney??&&data.needYfMoney)?string('checked',''))!''}> 需要预付款保函
							</label> <label class="checkbox-inline"> <input type="checkbox" name="needLyMoney" value="true"${((data.needLyMoney??&&data.needLyMoney)?string('checked',''))!''}> 需要履约保函
							</label>
						</div>
					</div>
					<div class="col-md-12 hidden zb-len">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 质保期（年）
									</div>
								</div>
								<input type="text" class="form-control number not-empty" name="zbLen" value="${data.zbLen!'1'}" placeholder="只能是整数" disabled="disabled">
								<div class="input-group-addon">年</div>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 结算方式
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="jiesuanWay" placeholder="最多500个汉字">${data.jiesuanWay}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 付款方式
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="fukuanWay" placeholder="最多500个汉字">${data.fukuanWay}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 工程内容
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="mainContent" placeholder="最多1000个汉字。">${data.mainContent}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span> 承包范围
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="chengbaoFanwei" placeholder="最多1000个汉字。">${data.chengbaoFanwei}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">备注</div>
								</div>
								<textarea rows="3" class="form-control" name="remark" placeholder="最多1000个汉字">${data.remark}</textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<hr style="margin-top: 5px;">
	</form>
</div>
</#if> </@t.body> <@t.foot>

<script type="text/javascript">
	require([ 'suredyModal', 'suredyTreeSelector', '${request.contextPath}/app/js/form-checker.js', 'jqueryForm', 'suredyDatetimepicker' ], function(Modal, Selector, formChecker) {
		// 提交合同信息
		$('a.submit-contract-info').on('click', function() {
			var form = $('form.form-create-contract');

			// 校验表单
			if (!formChecker(form)) {
				return false;
			}

			var cStart = $('[name="contractStart"]').val();
			var cEnd = $('[name="contractEnd"]').val();
			var cDays = $('[name="contractDays"]').val();

			if (!cStart && !cEnd && !cDays) {
				alert('【开工日期、竣工日期】与【工期天数】必须选择一类进行填写！');
				return false;
			} else if (!cDays) {
				if (!cStart || !cEnd) {
					alert('开工日期与竣工日期必须同时填写！');
					return false;
				}
			} else {
				if (cStart || cEnd) {
					alert('【开工日期、竣工日期】与【工期天数】只能选择一类进行填写！');
					return false;
				}
			}

			Modal.showProcessDialog({
				keyboard : false,
				text : '<div class="text-danger"><i class="icon-spinner icon-spin"></i>&nbsp;数据提交中，请稍候……</div>'
			});

			// 修复[买标书费用]、[投标保证金]的资金去向
			$('.money-source').val($('input[name="otherCompany"]').val());

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						var msg = (data && data.msg) || '信息修改失败!';
						alert(msg);
						Modal.closeProcessDialog();
						return false;
					}

					// notify config
					if ($.notifyDefaults) {
						$.notifyDefaults({
							allow_dismiss : false,
							placement : {
								align : 'center'
							},
							delay : 3000,
							mouse_over : 'pause',
							animate : {
								enter : 'animated flipInX',
								exit : 'animated flipOutX'
							}
						});
					}

					$.notify({
						title : '<span class="text-danger">提示！</span>',
						message : '信息修改成功！'
					});

					Modal.closeProcessDialog();

					window.opener.refresh();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('信息修改失败!\n' + errorThrown);
					Modal.closeProcessDialog();
					return false;
				}
			});
		});

		// 重置表单
		$('a.reset-form-info').on('click', function() {
			var form = $('form.form-create-contract');

			if (form.length > 0) {
				form[0].reset();
			}
		});

		var dom = $('[name="doUnit"]');
		Selector(dom, '${request.contextPath}/config/ou/tree/true/false/false', {
			multiselect : true,
			leafCheckbox : true,
			folderCheckbox : true,
			style : 'department'
		});
		dom.on(Selector.nodeClick, function() {
			var checked = Selector.checked(dom);

			dom.val('');

			$.each(checked, function(i, v) {
				var name = Selector.data(v, 'name');

				if (dom.val())
					dom.val(dom.val() + '；');

				dom.val(dom.val() + name);
			});

			dom.trigger('change');
		});
		dom.one(Selector.selectorShown, function() {
			var val = dom.val();

			$.each(Selector.nodes(dom), function(i, v) {
				var name = Selector.data(v, 'name');

				if (val.indexOf(name) != -1) {
					Selector.setActive(v, true);
				}
			});
		});

		{
			var $nzm = $('[name="needZbMoney"]');
			var zbLen = $('.zb-len');

			if ($nzm.is(':checked')) {
				zbLen.removeClass('hidden');
				zbLen.find('input').prop('disabled', false);
			} else {
				zbLen.addClass('hidden');
				zbLen.find('input').prop('disabled', true);
			}
		}
		$('[name="needZbMoney"]').on('change', function() {
			var $this = $(this);
			var zbLen = $('.zb-len');

			if ($this.is(':checked')) {
				zbLen.removeClass('hidden');
				zbLen.find('input').prop('disabled', false);
			} else {
				zbLen.addClass('hidden');
				zbLen.find('input').prop('disabled', true);
			}
		});
	});
</script>
</@t.foot>
